package ods_log

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"server/global"
	"server/model/common/request"
	"server/model/common/response"
)

type OdsDbSyncLogApi struct {
}

var odsDbSyncLogService = OdsDbSyncLogService{}

func (odsDbSyncLogApi *OdsDbSyncLogApi) CreateOdsDbSyncLog(c *gin.Context) {
	var odsDbSyncLog OdsDbSyncLog
	err := c.ShouldBindJSON(&odsDbSyncLog)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := odsDbSyncLogService.CreateOdsDbSyncLog(&odsDbSyncLog); err != nil {
		global.Logger.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}


func (odsDbSyncLogApi *OdsDbSyncLogApi) DeleteOdsDbSyncLog(c *gin.Context) {
	var odsDbSyncLog OdsDbSyncLog
	err := c.ShouldBindJSON(&odsDbSyncLog)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := odsDbSyncLogService.DeleteOdsDbSyncLog(odsDbSyncLog); err != nil {
		global.Logger.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}


func (odsDbSyncLogApi *OdsDbSyncLogApi) DeleteOdsDbSyncLogByIds(c *gin.Context) {
	var IDS request.IdsReq
	err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := odsDbSyncLogService.DeleteOdsDbSyncLogByIds(IDS); err != nil {
		global.Logger.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}


func (odsDbSyncLogApi *OdsDbSyncLogApi) UpdateOdsDbSyncLog(c *gin.Context) {
	var odsDbSyncLog OdsDbSyncLog
	err := c.ShouldBindJSON(&odsDbSyncLog)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := odsDbSyncLogService.UpdateOdsDbSyncLog(odsDbSyncLog); err != nil {
		global.Logger.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}


func (odsDbSyncLogApi *OdsDbSyncLogApi) FindOdsDbSyncLog(c *gin.Context) {
	var odsDbSyncLog OdsDbSyncLog
	err := c.ShouldBindQuery(&odsDbSyncLog)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if reodsDbSyncLog, err := odsDbSyncLogService.GetOdsDbSyncLogById(odsDbSyncLog.ID); err != nil {
		global.Logger.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reodsDbSyncLog": reodsDbSyncLog}, c)
	}
}


func (odsDbSyncLogApi *OdsDbSyncLogApi) GetOdsDbSyncLogList(c *gin.Context) {
	var pageInfo OdsDbSyncLogSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := odsDbSyncLogService.GetOdsDbSyncLogInfoList(pageInfo); err != nil {
		global.Logger.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}


func (odsDbSyncLogApi *OdsDbSyncLogApi) GetAllOdsDbSyncLogs(c *gin.Context) {
	odsDbSyncLog, err := odsDbSyncLogService.GetAllOdsDbSyncLogs()
	if err != nil {
		global.Logger.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(gin.H{"odsDbSyncLog": odsDbSyncLog}, "获取成功", c)
	}
}
